import requests
import time

def login():
    A = requests.Session()
    url = "http://118.121.200.162:8085/loginCheck.do"
    mydata = {
        "userID":"Razor0127",
        "password":"py324832"
    }
    res = A.post(url, data=mydata)
    assert res.status_code == 200
    return A

def getmessage():
    url = "http://118.121.200.162:8085/message/getMessageList"
    othercontent = {
        "messageID": 24,
         "userID": "yonghu",
        "content": "场馆怎么预约",
        "time": "2020-01-02 18:16:38",
         "userName": "1234",
        "picture": "",
        "state": 2
    }
    A = login()
    res = A.get(url, data=othercontent)
    assert res.status_code == 200
    assert "场馆怎么预约" in res.text
    return A

def sendmessage():
    url = "http://118.121.200.162:8085/sendMessage"
    now = time.strftime("%Y%m%d%H%M%S",time.localtime())
    mycontent = {
        "userID":"Razor0127",
        "content":"樊云霄的留言-" + now
    }
    A = login()
    res = A.post(url, data=mycontent)
    assert res.status_code == 200
    return A

def findUserList():
    url = "http://118.121.200.162:8085/message/findUserList"
    mymessage = {"messageID":32028,
                 "userID":"Razor0127",
                 "content":"樊云霄的留言-20221127111033",
                 "time":"2022-11-27 11:10:33",
                 "userName":"fyx",
                 "picture":"",
                 "state":1
                 }
    A = login()
    res = A.get(url, data=mymessage)
    print(res.text)
    assert res.status_code == 200
    messagetid = res.json()[0].get("messageID")
    return messagetid

messagetid  = findUserList()


# 请求方法delete
def delmessage():
    url = "http://118.121.200.162:8085/delMessage.do"
    data = {
        "messageID": messagetid
    }
    A = login()
    res = A.delete(url, data=data)
    assert res.status_code == 200
    assert "true" in res.text

login()
getmessage()
sendmessage()
findUserList()
delmessage()